﻿/// <reference path="../Core.ts" />

module Supernova {

    export class Body {
        //#warning do we really need code?
        //#warning can we make better lookups to bodies and ships?
        public code: number = 0;
        public system: StarSystem = null;
        public distance: number = 0;
        public initialAngle: number = 0;
        public angle: number = 0;
        public x: number = 0;
        public y: number = 0;
        public type: BodyType = BodyType.barren;
        public gold: number = 0;
        public population: number = 0;
        public maxPopulation: number = 0;
        public populationProgress: number = 0;
        public facilities: BodyFacilities = new BodyFacilities();
        public goodies: { gold: number; science: number } = { gold: 0, science: 0 };

        constructor(system: StarSystem, type: any = undefined) {
            this.system = system;
            this.type = type === undefined || type === null ? BodyType.barren : type;
        }

        describeInstalledFacilities(): string {
            var parts = [];
            if (this.facilities.scanner) parts.push('Scanner');
            if (this.facilities.mine) parts.push('Mine');
            if (this.facilities.science) parts.push('Research');
            if (this.facilities.comms) parts.push('Comms');
            if (this.facilities.shipyard) parts.push('Shipyard');
            if (this.facilities.artillery) parts.push('Artillery');
            if (this.facilities.orbitals > 0) parts.push(this.facilities.orbitals + ' Orbitals');
            var result = parts.join(', ');
            return result == '' ? 'None' : result;
        }

        depopulate() {
            this.population = 0;
            this.populationProgress = 0;
        }

        calculateGoldRate(includeMiningBase: boolean): number {
            var rate = (this.population | 0) * (this.facilities.comms ? galaxy.profile.gold.rate.withComms : galaxy.profile.gold.rate.noComms);
            if (includeMiningBase && this.gold > 0 && this.facilities.mine) {
                rate += galaxy.profile.gold.rate.withMines;
            }
            return rate;
        }
        
        calculateScienceRate(): number {
            return (this.population | 0) * (this.facilities.science ? galaxy.profile.science.rate.withFacility : galaxy.profile.science.rate.noFacility);
        }

    }

}